package com.qf.controller;/*
 *徐韬
 *2021/11/5
 *11:01
 */

import com.github.pagehelper.PageInfo;
import com.qf.cache.clientCache;
import com.qf.dto.R;
import com.qf.pojo.TClientBusiness;
import com.qf.service.clientService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/client")
@Api(tags = "公司信息")
public class clientController {
    private clientCache clientCache;
    private com.qf.service.clientService clientService;
@Autowired
    public void setClientService(com.qf.service.clientService clientService) {
        this.clientService = clientService;
    }

    @Autowired
    public void setClientCache(com.qf.cache.clientCache clientCache) {
        this.clientCache = clientCache;
    }
    @GetMapping("/showAll")
    public R showAll(@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue ="2") Integer pageSize){
        PageInfo<TClientBusiness> pageInfo = clientService.showAll(pageNum, pageSize);
        return R.setOk(pageInfo);

    }
    @GetMapping("/showById/{id}")
    public R showById(@PathVariable Long id){
        TClientBusiness clientBusiness = clientCache.getById(id);

        return R.setOk(clientBusiness);

    }
    @PostMapping("/add")
    public R add(@RequestBody TClientBusiness tClientBusiness){
    clientService.add(tClientBusiness);
    return R.setOk();

    }
    @PostMapping("/update")
    public R update(@RequestBody TClientBusiness tClientBusiness){
    clientService.update(tClientBusiness);
    return R.setOk();
    }
    @DeleteMapping("delete")
    public R delete(@RequestBody Map map){
        List<Integer> ids = (List<Integer>) map.get("ids");
        clientService.deleteByIds(ids);
        return R.setOk();

    }
}
